package com.appspot.categoryeditor.service;

import java.util.Date;

import org.slim3.datastore.Datastore;

import com.appspot.categoryeditor.meta.UserMeta;
import com.appspot.categoryeditor.model.User;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Transaction;

public class UserService {
	final static UserMeta USER_META = UserMeta.get();

	public boolean checkUserExist(String userid){
		Key userKey = Datastore.createKey(USER_META, userid);
		return Datastore.query(USER_META, userKey).count() > 0;
	}
	
	public User addÜser(Transaction tx, String userid){
		User user = new User();
		Key userKey = Datastore.createKey(USER_META, userid);
		user.setId(userKey);
		user.setCreated(new Date());
		Datastore.put(tx, user);
		
		return user;
	}
}
